package com.dy.scs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dy.scs.mapper.CourseMapper;
import com.dy.scs.pojo.Course;
import com.dy.scs.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public Page<Course> pages(Integer pages, Integer pageSize,String cname,String sortBy,String sortType) {
        Page<Course> page=new Page<>(pages,pageSize);
        QueryWrapper<Course> queryWrapper=new QueryWrapper<>();
        if(cname!=null&&!cname.isEmpty()){
            queryWrapper.like("cname",cname);
        }
        if(sortBy!=null&&!sortBy.isEmpty()){
            if("asc".equalsIgnoreCase(sortType)){
                queryWrapper.orderByAsc(sortBy);
            }
            if("desc".equalsIgnoreCase(sortType)){
                queryWrapper.orderByDesc(sortBy);
            }
        }
        return page(page,queryWrapper);
    }

}
